You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TTFFileTestCase.java 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.fonts.truetype;
  19. import java.io.FileInputStream;
  20. import java.io.IOException;
  21. import java.io.InputStream;
  22. import java.util.List;
  23. import java.util.Map;
  24. import org.junit.Test;
  25. import static org.junit.Assert.assertEquals;
  26. import static org.junit.Assert.assertTrue;
  27. import static org.junit.Assert.fail;
  28. import org.apache.fop.fonts.CMapSegment;
  29. import org.apache.fop.fonts.truetype.OpenFont.PostScriptVersion;
  30. /**
  31. * Class for testing org.apache.fop.fonts.truetype.TTFFile
  32. */
  33. public class TTFFileTestCase {
  34. // We only want to initialize the FontFileReader once (for performance reasons)
  35. /** The truetype font file (DejaVuLGCSerif) */
  36. protected final TTFFile dejavuTTFFile;
  37. /** The FontFileReader for ttfFile (DejaVuLGCSerif) */
  38. protected final FontFileReader dejavuReader;
  39. /** The truetype font file (DroidSansMono) */
  40. protected final TTFFile droidmonoTTFFile;
  41. /** The FontFileReader for ttfFile (DroidSansMono) */
  42. protected final FontFileReader droidmonoReader;
  43. /** The truetype font file (AndroidEmoji) fonr non-BMP codepoints */
  44. protected final TTFFile androidEmojiTTFFile;
  45. /** The FontFileReader for ttfFile (AndroidEmoji) */
  46. protected final FontFileReader androidEmojiReader;
  47. /**
  48. * Constructor initialises FileFontReader to
  49. * @throws IOException exception
  50. */
  51. public TTFFileTestCase() throws IOException {
  52. InputStream dejaStream = new FileInputStream("test/resources/fonts/ttf/DejaVuLGCSerif.ttf");
  53. dejavuTTFFile = new TTFFile();
  54. dejavuReader = new FontFileReader(dejaStream);
  55. String dejavuHeader = OFFontLoader.readHeader(dejavuReader);
  56. dejavuTTFFile.readFont(dejavuReader, dejavuHeader);
  57. dejaStream.close();
  58. InputStream droidStream = new FileInputStream("test/resources/fonts/ttf/DroidSansMono.ttf");
  59. droidmonoTTFFile = new TTFFile();
  60. droidmonoReader = new FontFileReader(droidStream);
  61. String droidmonoHeader = OFFontLoader.readHeader(droidmonoReader);
  62. droidmonoTTFFile.readFont(droidmonoReader, droidmonoHeader);
  63. droidStream.close();
  64. InputStream emojiStream = new FileInputStream("test/resources/fonts/ttf/AndroidEmoji.ttf");
  65. androidEmojiTTFFile = new TTFFile();
  66. androidEmojiReader = new FontFileReader(emojiStream);
  67. String androidEmojiHeader = OFFontLoader.readHeader(androidEmojiReader);
  68. androidEmojiTTFFile.readFont(androidEmojiReader, androidEmojiHeader);
  69. emojiStream.close();
  70. }
  71. /**
  72. * Test convertTTFUnit2PDFUnit() - The units per em retrieved reading the HEAD table from
  73. * the font file. (DroidSansMono has the same units per em as DejaVu so no point testing it)
  74. */
  75. @Test
  76. public void testConvertTTFUnit2PDFUnit() {
  77. // DejaVu has 2048 units per em (PDF works in millipts, thus the 1000)
  78. // test rational number
  79. assertEquals(1000, dejavuTTFFile.convertTTFUnit2PDFUnit(2048));
  80. // test smallest case, this should = 0.488 (round down to 0)
  81. assertEquals(0, dejavuTTFFile.convertTTFUnit2PDFUnit(1));
  82. // this should round up, but since it's millipts...
  83. assertEquals(0, dejavuTTFFile.convertTTFUnit2PDFUnit(2));
  84. // ensure behaviour is the same for negative numbers
  85. assertEquals(0, dejavuTTFFile.convertTTFUnit2PDFUnit(-0));
  86. assertEquals(-1000, dejavuTTFFile.convertTTFUnit2PDFUnit(-2048));
  87. assertEquals(0, dejavuTTFFile.convertTTFUnit2PDFUnit(-1));
  88. assertEquals(0, dejavuTTFFile.convertTTFUnit2PDFUnit(-2));
  89. }
  90. /**
  91. * Test checkTTC()
  92. * @throws IOException exception
  93. */
  94. @Test
  95. public void testCheckTTC() throws IOException {
  96. // DejaVu is not a TTC, thus this returns true
  97. String dejavuHeader = OFFontLoader.readHeader(dejavuReader);
  98. assertTrue(dejavuTTFFile.checkTTC(dejavuHeader, ""));
  99. String droidmonoHeader = OFFontLoader.readHeader(droidmonoReader);
  100. assertTrue(droidmonoTTFFile.checkTTC(droidmonoHeader, ""));
  101. /*
  102. * Cannot reasonably test the rest of this method without an actual truetype collection
  103. * because all methods in FontFileReader are "final" and thus mocking isn't possible.
  104. */
  105. }
  106. /**
  107. * Test getAnsiKerning() - Tests values retrieved from the kern table in the font file.
  108. */
  109. @Test
  110. public void testGetAnsiKerning() {
  111. Map<Integer, Map<Integer, Integer>> ansiKerning = dejavuTTFFile.getAnsiKerning();
  112. if (ansiKerning.isEmpty()) {
  113. fail();
  114. }
  115. Integer k1 = ansiKerning.get((int) 'A').get((int) 'T');
  116. assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(-112), k1.intValue());
  117. Integer k2 = ansiKerning.get((int) 'Y').get((int) 'u');
  118. assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(-178), k2.intValue());
  119. // DroidSansMono doens't have kerning (it's mono-spaced)
  120. ansiKerning = droidmonoTTFFile.getAnsiKerning();
  121. if (!ansiKerning.isEmpty()) {
  122. fail("DroidSansMono shouldn't have any kerning data.");
  123. }
  124. // AndroidEmoji doens't have kerning
  125. ansiKerning = androidEmojiTTFFile.getAnsiKerning();
  126. if (!ansiKerning.isEmpty()) {
  127. fail("AndroidEmoji shouldn't have any kerning data.");
  128. }
  129. }
  130. /**
  131. * Test getCapHeight - there are several paths to test:
  132. * 1) The PCLT table (if present)
  133. * 2) The yMax (3rd) value, for the bounding box, for 'H' in the glyf table.
  134. * if not the above:
  135. * 3) The caps height in the OS/2 table
  136. * Tests values retrieved from analysing the font file.
  137. */
  138. @Test
  139. public void testGetCapHeight() {
  140. // DejaVu doesn't have the PCLT table and so these have to be guessed
  141. // The height is approximated to be the height of the "H" which for
  142. // Deja = 1493 TTFunits
  143. assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(1493), dejavuTTFFile.getCapHeight());
  144. // DroidSansMono doesn't have a PCLT table either
  145. // height of "H" = 1462
  146. assertEquals(droidmonoTTFFile.convertTTFUnit2PDFUnit(1462),
  147. droidmonoTTFFile.getCapHeight());
  148. // AndroidEmoji doesn't have a PCLT table either
  149. // height of "H" = 1462
  150. assertEquals(androidEmojiTTFFile.convertTTFUnit2PDFUnit(1462),
  151. androidEmojiTTFFile.getCapHeight());
  152. }
  153. /**
  154. * Test getCharSetName() - check that it returns "WinAnsiEncoding".
  155. */
  156. @Test
  157. public void testGetCharSetName() {
  158. assertTrue("WinAnsiEncoding".equals(dejavuTTFFile.getCharSetName()));
  159. assertTrue("WinAnsiEncoding".equals(droidmonoTTFFile.getCharSetName()));
  160. //Even though this pass I'm not sure whether is what we want
  161. assertTrue("WinAnsiEncoding".equals(androidEmojiTTFFile.getCharSetName()));
  162. }
  163. /**
  164. * Test getCharWidth() - Test values retrieved from the metrics in the glyf table in
  165. * the font file.
  166. */
  167. @Test
  168. public void testGetCharWidth() {
  169. // Arbitrarily test a few values:
  170. // The width of "H" (Unicode index 0x0048) is 1786
  171. assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(1786), dejavuTTFFile.getCharWidth(0x48));
  172. // The width of "i" (unicode index 0x0069) is 655 TTFunits
  173. assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(655), dejavuTTFFile.getCharWidth(0x69));
  174. // final check, "!" (unicode index 0x0021) is 823 TTFunits
  175. assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(823), dejavuTTFFile.getCharWidth(0x21));
  176. // All the glyphs should be the same width in DroidSansMono (mono-spaced)
  177. int charWidth = droidmonoTTFFile.convertTTFUnit2PDFUnit(1229);
  178. for (int i = 0; i < 255; i++) {
  179. assertEquals(charWidth, droidmonoTTFFile.getCharWidth(i));
  180. }
  181. // All the glyphs should be the same width in EmojiAndroid (mono-spaced)
  182. charWidth = androidEmojiTTFFile.convertTTFUnit2PDFUnit(2600);
  183. for (int i = 0; i < 255; i++) {
  184. assertEquals(charWidth, androidEmojiTTFFile.getCharWidth(i));
  185. }
  186. }
  187. /**
  188. * TODO: add implementation to this test
  189. */
  190. @Test
  191. public void testGetCMaps() {
  192. List<CMapSegment> cmaps = androidEmojiTTFFile.getCMaps();
  193. for (CMapSegment seg : cmaps) {
  194. System.out.println(seg.getUnicodeStart() + "-" + seg.getUnicodeEnd() + " -> " + seg.getGlyphStartIndex());
  195. }
  196. }
  197. /**
  198. * Test getFamilyNames() - Test value retrieved from the name table in the font file.
  199. */
  200. @Test
  201. public void testGetFamilyNames() {
  202. assertEquals(1, dejavuTTFFile.getFamilyNames().size());
  203. for (String name : dejavuTTFFile.getFamilyNames()) {
  204. assertEquals("DejaVu LGC Serif", name);
  205. }
  206. assertEquals(1, droidmonoTTFFile.getFamilyNames().size());
  207. for (String name : droidmonoTTFFile.getFamilyNames()) {
  208. assertEquals("Droid Sans Mono", name);
  209. }
  210. assertEquals(1, androidEmojiTTFFile.getFamilyNames().size());
  211. for (String name : androidEmojiTTFFile.getFamilyNames()) {
  212. assertEquals("Android Emoji", name);
  213. }
  214. }
  215. /**
  216. * Test getFirstChar() - TODO: implement a more intelligent test here.
  217. */
  218. @Test
  219. public void testGetFirstChar() {
  220. // Not really sure how to test this intelligently
  221. assertEquals(0, dejavuTTFFile.getFirstChar());
  222. assertEquals(0, droidmonoTTFFile.getFirstChar());
  223. assertEquals(0, androidEmojiTTFFile.getFirstChar());
  224. }
  225. /**
  226. * Test getFlags() - Test values retrieved from the POST table in the font file.
  227. */
  228. @Test
  229. public void testGetFlags() {
  230. /* DejaVu flags are:
  231. * italic angle = 0
  232. * fixed pitch = 0
  233. * has serifs = true (default value; this font doesn't have a PCLT table)
  234. */
  235. int flags = dejavuTTFFile.getFlags();
  236. assertEquals(0, flags & 64); // Italics angle = 0
  237. assertEquals(32, flags & 32); // Adobe standard charset
  238. assertEquals(0, flags & 2); // fixed pitch = 0
  239. assertEquals(1, flags & 1); // has serifs = 1 (true)
  240. /*
  241. * Droid flags are:
  242. * italic angle = 0
  243. * fixed pitch = 1
  244. * has serifs = true (default value; this font doesn't have a PCLT table)
  245. */
  246. flags = droidmonoTTFFile.getFlags();
  247. assertEquals(0, flags & 64);
  248. assertEquals(32, flags & 32);
  249. assertEquals(2, flags & 2);
  250. assertEquals(1, flags & 1);
  251. /*
  252. * Android Emoji flags are:
  253. * italic angle = 0
  254. * fixed pitch = 0
  255. * has serifs = true (default value; this font doesn't have a PCLT table)
  256. */
  257. flags = androidEmojiTTFFile.getFlags();
  258. assertEquals(0, flags & 64);
  259. assertEquals(32, flags & 32);
  260. assertEquals(0, flags & 2);
  261. assertEquals(1, flags & 1);
  262. }
  263. /**
  264. * Test getFontBBox() - Test values retrieved from values in the HEAD table in the font file.
  265. */
  266. @Test
  267. public void testGetFontBBox() {
  268. int[] bBox = dejavuTTFFile.getFontBBox();
  269. /*
  270. * The head table has the following values(DejaVu):
  271. * xmin = -1576, ymin = -710, xmax = 3439, ymax = 2544
  272. */
  273. assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(-1576), bBox[0]);
  274. assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(-710), bBox[1]);
  275. assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(3439), bBox[2]);
  276. assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(2544), bBox[3]);
  277. /*
  278. * The head table has the following values (DroidSansMono):
  279. * xmin = -312, ymin= -555, xmax = 1315, ymax = 2163
  280. */
  281. bBox = droidmonoTTFFile.getFontBBox();
  282. assertEquals(droidmonoTTFFile.convertTTFUnit2PDFUnit(-312), bBox[0]);
  283. assertEquals(droidmonoTTFFile.convertTTFUnit2PDFUnit(-555), bBox[1]);
  284. assertEquals(droidmonoTTFFile.convertTTFUnit2PDFUnit(1315), bBox[2]);
  285. assertEquals(droidmonoTTFFile.convertTTFUnit2PDFUnit(2163), bBox[3]);
  286. /*
  287. * The head table has the following values (DroidSansMono):
  288. * xMin = -50, yMin = -733, xMax = 2550, yMax = 2181
  289. */
  290. bBox = androidEmojiTTFFile.getFontBBox();
  291. assertEquals(androidEmojiTTFFile.convertTTFUnit2PDFUnit(-50), bBox[0]);
  292. assertEquals(androidEmojiTTFFile.convertTTFUnit2PDFUnit(-733), bBox[1]);
  293. assertEquals(androidEmojiTTFFile.convertTTFUnit2PDFUnit(2550), bBox[2]);
  294. assertEquals(androidEmojiTTFFile.convertTTFUnit2PDFUnit(2181), bBox[3]);
  295. }
  296. /**
  297. * Test getFullName() - Test value retrieved from the name table in the font file.
  298. */
  299. @Test
  300. public void testGetFullName() {
  301. assertEquals("DejaVu LGC Serif", dejavuTTFFile.getFullName());
  302. assertEquals("Droid Sans Mono", droidmonoTTFFile.getFullName());
  303. assertEquals("Android Emoji", androidEmojiTTFFile.getFullName());
  304. }
  305. /**
  306. * Test getGlyphName - Test value retrieved from the POST table in the font file.
  307. */
  308. @Test
  309. public void testGetGlyphName() {
  310. assertEquals("H", dejavuTTFFile.getGlyphName(43));
  311. assertEquals("H", droidmonoTTFFile.getGlyphName(43));
  312. assertEquals("smileface", androidEmojiTTFFile.getGlyphName(64));
  313. }
  314. /**
  315. * Test getItalicAngle() - Test value retrieved from the POST table in the font file.
  316. */
  317. @Test
  318. public void testGetItalicAngle() {
  319. assertEquals("0", dejavuTTFFile.getItalicAngle());
  320. assertEquals("0", droidmonoTTFFile.getItalicAngle());
  321. assertEquals("0", androidEmojiTTFFile.getItalicAngle());
  322. }
  323. /**
  324. * Test getKerning() - Test values retrieved from the kern table in the font file.
  325. */
  326. @Test
  327. public void testGetKerning() {
  328. Map<Integer, Map<Integer, Integer>> kerning = dejavuTTFFile.getKerning();
  329. if (kerning.isEmpty()) {
  330. fail();
  331. }
  332. Integer k1 = kerning.get((int) 'A').get((int) 'T');
  333. assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(-112), k1.intValue());
  334. Integer k2 = kerning.get((int) 'K').get((int) 'u');
  335. assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(-45), k2.intValue());
  336. // DroidSansMono has no kerning data (mono-spaced)
  337. kerning = droidmonoTTFFile.getKerning();
  338. if (!kerning.isEmpty()) {
  339. fail("DroidSansMono shouldn't have any kerning data");
  340. }
  341. // AndroidEmoji doens't have kerning
  342. kerning = androidEmojiTTFFile.getKerning();
  343. if (!kerning.isEmpty()) {
  344. fail("AndroidEmoji shouldn't have any kerning data.");
  345. }
  346. }
  347. /**
  348. * Test lastChar() - TODO: implement a more intelligent test
  349. */
  350. @Test
  351. public void testLastChar() {
  352. assertEquals(0xff, dejavuTTFFile.getLastChar());
  353. assertEquals(0xff, droidmonoTTFFile.getLastChar());
  354. assertEquals(0xae, androidEmojiTTFFile.getLastChar()); // Last ASCII mapped char is REGISTERED SIGN
  355. }
  356. /**
  357. * Test getLowerCaseAscent() - There are several paths to test:
  358. * 1) The values in the HHEA table (see code)
  359. * 2) Fall back to values from the OS/2 table
  360. * Test values retrieved from the font file.
  361. */
  362. @Test
  363. public void testGetLowerCaseAscent() {
  364. assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(1556),
  365. dejavuTTFFile.getLowerCaseAscent());
  366. // Curiously the same value
  367. assertEquals(droidmonoTTFFile.convertTTFUnit2PDFUnit(1556),
  368. droidmonoTTFFile.getLowerCaseAscent());
  369. //TODO: Nedd to be fixed?
  370. // 0 because the font miss letter glyph that are used in this method to guess the ascender:
  371. // OpenFont.guessVerticalMetricsFromGlyphBBox
  372. assertEquals(androidEmojiTTFFile.convertTTFUnit2PDFUnit(0),
  373. androidEmojiTTFFile.getLowerCaseAscent());
  374. }
  375. /**
  376. * Test getPostScriptName() - Test values retrieved from the post table in the font file.
  377. */
  378. @Test
  379. public void testGetPostScriptName() {
  380. assertEquals(PostScriptVersion.V2, dejavuTTFFile.getPostScriptVersion());
  381. assertEquals(PostScriptVersion.V2, droidmonoTTFFile.getPostScriptVersion());
  382. assertEquals(PostScriptVersion.V2, androidEmojiTTFFile.getPostScriptVersion());
  383. }
  384. /**
  385. * Test getStemV() - Undefined.
  386. */
  387. @Test
  388. public void testGetStemV() {
  389. // Undefined
  390. assertEquals("0", dejavuTTFFile.getStemV());
  391. assertEquals("0", droidmonoTTFFile.getStemV());
  392. assertEquals("0", androidEmojiTTFFile.getStemV());
  393. }
  394. /**
  395. * Test getSubFamilyName() - Test values retrieved from the name table in the font file.
  396. */
  397. @Test
  398. public void testGetSubFamilyName() {
  399. assertEquals("Book", dejavuTTFFile.getSubFamilyName());
  400. assertEquals("Regular", droidmonoTTFFile.getSubFamilyName());
  401. assertEquals("Regular", androidEmojiTTFFile.getSubFamilyName());
  402. }
  403. /**
  404. * Test getTTCnames() - TODO: add implementation with TTC font.
  405. */
  406. public void testGetTTCnames() {
  407. // Can't test with with DejaVu since it's not a TrueType Collection
  408. }
  409. /**
  410. * Test getWeightClass() - Test value retrieved from the OS/2 table in the font file.
  411. */
  412. @Test
  413. public void testGetWeightClass() {
  414. // Retrieved from OS/2 table
  415. assertEquals(400, dejavuTTFFile.getWeightClass());
  416. assertEquals(400, droidmonoTTFFile.getWeightClass());
  417. assertEquals(400, androidEmojiTTFFile.getWeightClass());
  418. }
  419. /**
  420. * Test getWidths() - Test values retrieved from the hmtx table in the font file.
  421. */
  422. @Test
  423. public void testGetWidths() {
  424. int[] widths = dejavuTTFFile.getWidths();
  425. // using the width of 'A' index = 36
  426. assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(1479), widths[36]);
  427. // using the width of '|' index = 95
  428. assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(690), widths[95]);
  429. // DroidSansMono should have all widths the same size (mono-spaced)
  430. widths = droidmonoTTFFile.getWidths();
  431. int charWidth = droidmonoTTFFile.convertTTFUnit2PDFUnit(1229);
  432. for (OpenFont.UnicodeMapping unicodeMapping : droidmonoTTFFile.unicodeMappings) {
  433. assertEquals(charWidth, widths[unicodeMapping.getGlyphIndex()]);
  434. }
  435. // All the glyphs should be the same width in EmojiAndroid (mono-spaced)
  436. charWidth = androidEmojiTTFFile.convertTTFUnit2PDFUnit(2600);
  437. widths = androidEmojiTTFFile.getWidths();
  438. for (OpenFont.UnicodeMapping unicodeMapping : androidEmojiTTFFile.unicodeMappings) {
  439. assertEquals(charWidth, widths[unicodeMapping.getGlyphIndex()]);
  440. }
  441. }
  442. @Test
  443. public void textUnicodeCoverage() {
  444. int nonBMPcount = 0;
  445. for (OpenFont.UnicodeMapping unicodeMapping : droidmonoTTFFile.unicodeMappings) {
  446. nonBMPcount += unicodeMapping.getUnicodeIndex() > 0xFFFF ? 1 : 0;
  447. }
  448. assertEquals("The font DroidSansMono is supposed to have only BMP codepoints", 0, nonBMPcount);
  449. nonBMPcount = 0;
  450. for (OpenFont.UnicodeMapping unicodeMapping : androidEmojiTTFFile.unicodeMappings) {
  451. nonBMPcount += unicodeMapping.getUnicodeIndex() > 0xFFFF ? 1 : 0;
  452. }
  453. assertTrue("The font AndroidEmoji is supposed to have non-BMP codepoints", 0 != nonBMPcount);
  454. }
  455. /**
  456. * Test getXHeight() - There are several paths to test:
  457. * 1) The PCLT table (if available)
  458. * 2) The yMax for the bounding box for 'x' in the glyf table.
  459. * Fall back:
  460. * 3) The xheight in the OS/2 table.
  461. */
  462. @Test
  463. public void testGetXHeight() {
  464. // Since there's no PCLT table, the height of 'x' is used for both DejaVu and DroidSansMono
  465. assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(1064), dejavuTTFFile.getXHeight());
  466. assertEquals(droidmonoTTFFile.convertTTFUnit2PDFUnit(1098), droidmonoTTFFile.getXHeight());
  467. }
  468. /**
  469. * Test isCFF() - TODO: add test for a CFF font.
  470. */
  471. @Test
  472. public void testIsCFF() {
  473. // Neither DejaVu nor DroidSansMono are a compact format font
  474. assertEquals(false, dejavuTTFFile.isCFF());
  475. assertEquals(false, droidmonoTTFFile.isCFF());
  476. assertEquals(false, androidEmojiTTFFile.isCFF());
  477. }
  478. /**
  479. * Test isEmbeddable() - Test value retrieved from the OS/2 table in the font file.
  480. */
  481. @Test
  482. public void testIsEmbeddable() {
  483. // Dejavu and DroidSansMono are both embeddable
  484. assertEquals(true, dejavuTTFFile.isEmbeddable());
  485. assertEquals(true, droidmonoTTFFile.isEmbeddable());
  486. assertEquals(true, androidEmojiTTFFile.isEmbeddable());
  487. }
  488. /** Underline position and thickness. */
  489. @Test
  490. public void testUnderline() {
  491. assertEquals(-63, dejavuTTFFile.getUnderlinePosition());
  492. assertEquals(43, dejavuTTFFile.getUnderlineThickness());
  493. assertEquals(-75, droidmonoTTFFile.getUnderlinePosition());
  494. assertEquals(49, droidmonoTTFFile.getUnderlineThickness());
  495. assertEquals(-75, androidEmojiTTFFile.getUnderlinePosition());
  496. assertEquals(49, androidEmojiTTFFile.getUnderlineThickness());
  497. }
  498. /** Strikeout position and thickness. */
  499. @Test
  500. public void testStrikeout() {
  501. assertEquals(258, dejavuTTFFile.getStrikeoutPosition());
  502. assertEquals(49, dejavuTTFFile.getStrikeoutThickness());
  503. assertEquals(243, droidmonoTTFFile.getStrikeoutPosition());
  504. assertEquals(49, droidmonoTTFFile.getStrikeoutThickness());
  505. assertEquals(122, androidEmojiTTFFile.getStrikeoutPosition());
  506. assertEquals(24, androidEmojiTTFFile.getStrikeoutThickness());
  507. }
  508. /**
  509. * Test readFont() - Add implementation if necessary.
  510. */
  511. public void testReadFont() {
  512. // I'm pretty sure we've tested this with all the other tests
  513. }
  514. @Test
  515. public void testBBox() {
  516. assertEquals(dejavuTTFFile.getBBox(1)[0], 49);
  517. assertEquals(dejavuTTFFile.getBBox(2330).length, 4);
  518. }
  519. }