Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
- move fonts to tests resources directory
- remove Intel Clear-Light
- add W3C unit test font Ahem
- add new font info test

fixes #117
  • Loading branch information
bsweeney authored Jan 6, 2024
1 parent cca2a59 commit 41489fb
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 10 deletions.
Binary file removed sample-fonts/IntelClear-Light.ttf
Binary file not shown.
Binary file removed sample-fonts/NotoSansShavian-Regular.ttf
Binary file not shown.
33 changes: 23 additions & 10 deletions tests/FontLib/FontTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,30 @@ public function testLoadFileNotFound()
}
}

public function testLoadTTFFontSuccessfully()
public function testLoadTTFFont()
{
$trueTypeFont = Font::load('sample-fonts/IntelClear-Light.ttf');
$trueTypeFont = Font::load('tests/resources/fonts/ahem/ahem.ttf');

$this->assertInstanceOf('FontLib\TrueType\File', $trueTypeFont);
}

public function test12CmapFormat()
public function testGetFontInfoTTF()
{
$trueTypeFont = Font::load('sample-fonts/NotoSansShavian-Regular.ttf');
$font = Font::load('tests/resources/fonts/ahem/ahem.ttf');
$font->parse();
$this->assertSame('Ahem', $font->getFontName());
$this->assertSame('Regular', $font->getFontSubfamily());
$this->assertSame('Version 1.50 Ahem', $font->getFontSubfamilyID());
$this->assertSame('Ahem', $font->getFontFullName());
$this->assertSame('Version 1.50', $font->getFontVersion());
$this->assertSame(400, $font->getFontWeight());
$this->assertSame('Ahem', $font->getFontPostscriptName());
$this->assertTrue($font->close());
}

public function testTTFCmap()
{
$trueTypeFont = Font::load('tests/resources/fonts/noto/NotoSansShavian-Regular.ttf');

$trueTypeFont->parse();

Expand All @@ -40,17 +54,16 @@ public function test12CmapFormat()
$cmapFormat4Table = $cmapTable[0];

$this->assertEquals(4, $cmapFormat4Table['format']);
$this->assertEquals(6, $cmapFormat4Table['segCount']);
$this->assertEquals(51, $cmapFormat4Table['segCount']);
$this->assertEquals($cmapFormat4Table['segCount'], count($cmapFormat4Table['startCode']));
$this->assertEquals($cmapFormat4Table['segCount'], count($cmapFormat4Table['endCode']));

$cmapFormat12Table = $cmapTable[1];

$this->assertEquals(12, $cmapFormat12Table['format']);
$this->assertEquals(6, $cmapFormat12Table['ngroups']);
$this->assertEquals(6, count($cmapFormat12Table['startCode']));
$this->assertEquals(6, count($cmapFormat12Table['endCode']));
$this->assertEquals(53, count($cmapFormat12Table['glyphIndexArray']));
$this->assertEquals(294, $cmapFormat12Table['ngroups']);
$this->assertEquals(294, count($cmapFormat12Table['startCode']));
$this->assertEquals(294, count($cmapFormat12Table['endCode']));
$this->assertEquals(383, count($cmapFormat12Table['glyphIndexArray']));
}

}
4 changes: 4 additions & 0 deletions tests/resources/fonts/ahem/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The Ahem font belongs to the public domain. In jurisdictions that do
not recognize public domain ownership of these files, the following
Creative Commons Zero declaration applies:
http://labs.creativecommons.org/licenses/zero-waive/1.0/us/legalcode
93 changes: 93 additions & 0 deletions tests/resources/fonts/ahem/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
The Ahem font was developed by Todd Fahrner and Myles C. Maxfield to
help test writers develop predictable tests. The units per em is 1000,
the ascent is 800, and the descent is 200, thereby making the em
square exactly square. The glyphs for most characters is simply a box
which fills this square. The codepoints mapped to this full square
with a full advance are the following ranges:

U+20-U+26
U+28-U+6F
U+71-U+7E
U+A0-U+C8
U+CA-U+FF
U+131
U+152-U+153
U+178
U+192
U+2C6-U+2C7
U+2C9
U+2D8-U+2DD
U+394
U+3A5
U+3A7
U+3A9
U+3BC
U+3C0
U+2013-U+2014
U+2018-U+201A
U+201C-U+201E
U+2020-U+2022
U+2026
U+2030
U+2039-U+203A
U+2044
U+2122
U+2126
U+2202
U+2206
U+220F
U+2211-U+2212
U+2219-U+221A
U+221E
U+222B
U+2248
U+2260
U+2264-U+2265
U+22F2
U+25CA
U+3007
U+4E00
U+4E03
U+4E09
U+4E5D
U+4E8C
U+4E94
U+516B
U+516D
U+5341
U+56D7
U+56DB
U+571F
U+6728
U+6C34
U+706B
U+91D1
U+F000-U+F002

The codepoints which are mapped to something else are the following:

" " (U+20): No path but full advance
"p" (U+70): Path has 0 ascent but full descent
"É" (U+C9): Path has 0 descent but full ascent
Non-breaking space (U+A0): No path but full advance
Zero-width non-breaking space (U+FEFF): No path and 0 advance
En space (U+2002): No path and half advance
Em space (U+2003): No path but full advance
Three-per-em space (U+2004): No path and one third advance
Four-per-em space (U+2005): No path and one quarter advance
Six-per-em space (U+2006): No path and one sixth advance
Thin space (U+2009): No path and one fifth advance
Hair space (U+200A): No path and one tenth advance
Zero width space (U+200B): No path and no advance
Ideographic space (U+3000): No path but full advance
Zero width non-joiner (U+200C): No path and no advance
Zero width joiner (U+200D): No path and no advance
Greek capital letter Upsilon (U+3A5): Thin vertical stripe and full advance
Greek capital letter Chi (U+3A7): Thin horizontal stripe and full advance
"横" (U+6A2A): Thin horizontal stripe and full advance
"橫" (U+6A6B): Thin horizontal stripe and full advance;
"縦" (U+7E26): Thin vertical stripe and full advance;
"縱" (U+7E31): Thin vertical stripe and full advance;
"纵" (U+7EB5): Thin vertical stripe and full advance.

Source: https://www.w3.org/Style/CSS/Test/Fonts/Ahem/
Binary file added tests/resources/fonts/ahem/ahem.ttf
Binary file not shown.
93 changes: 93 additions & 0 deletions tests/resources/fonts/noto/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Copyright 2022 The Noto Project Authors

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
https://scripts.sil.org/OFL


-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file not shown.
22 changes: 22 additions & 0 deletions tests/resources/fonts/noto/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Noto Sans Shavian is an unmodulated (“sans serif”) design for texts in the
historical artificial _Shavian_ script.

Noto Sans Shavian contains 53 glyphs, and supports 52 characters from the
Unicode block Shavian.

### Supported writing systems
#### Shavian

Shavian (𐑖𐑱𐑝𐑾𐑯 𐑨𐑤𐑓𐑩𐑚𐑧𐑑) is an artificial alphabet, written left-to-right.
Created around 1960 by Ronald Kingsley Read for phonetic spelling of
English. The winning entry in a competition posthumously funded by
playwright Bernard Shaw. Also adopted for Esperanto.

Needs software support for complex text layout (shaping). Read more on
[ScriptSource](https://scriptsource.org/scr/Shaw),
[Unicode](https://www.unicode.org/versions/Unicode13.0.0/ch08.pdf#G27260),
[Wikipedia](https://en.wikipedia.org/wiki/ISO_15924:Shaw),
[Wiktionary](https://en.wiktionary.org/wiki/Category:Shavian_script),
[r12a](https://r12a.github.io/scripts/links?iso=Shaw).

Source: https://github.com/google/fonts/tree/main/ofl/notosansshavian

0 comments on commit 41489fb

Please sign in to comment.