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.

OTFFileTestCase.java 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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.awt.Rectangle;
  20. import java.io.FileInputStream;
  21. import java.io.InputStream;
  22. import org.junit.Before;
  23. import org.junit.Test;
  24. import static org.junit.Assert.assertEquals;
  25. import static org.junit.Assert.assertTrue;
  26. public class OTFFileTestCase {
  27. protected OTFFile sourceSansProBold;
  28. protected FontFileReader sourceSansReader;
  29. protected OTFFile alexBrush;
  30. protected FontFileReader alexBrushReader;
  31. /**
  32. * Initializes fonts used for the testing of reading OTF CFF
  33. * @throws java.io.IOException
  34. */
  35. @Before
  36. public void setUp() throws Exception {
  37. sourceSansProBold = new OTFFile();
  38. InputStream sourceSansStream = new FileInputStream("test/resources/fonts/otf/SourceSansProBold.otf");
  39. sourceSansReader = new FontFileReader(sourceSansStream);
  40. String sourceSansHeader = OFFontLoader.readHeader(sourceSansReader);
  41. sourceSansProBold.readFont(sourceSansReader, sourceSansHeader);
  42. sourceSansStream.close();
  43. InputStream alexBrushStream = new FileInputStream("test/resources/fonts/otf/AlexBrushRegular.otf");
  44. alexBrush = new OTFFile();
  45. alexBrushReader = new FontFileReader(alexBrushStream);
  46. String carolynaHeader = OFFontLoader.readHeader(alexBrushReader);
  47. alexBrush.readFont(alexBrushReader, carolynaHeader);
  48. alexBrushStream.close();
  49. }
  50. /**
  51. * Tests the font names being read from the file
  52. */
  53. @Test
  54. public void testFontNames() {
  55. assertTrue(sourceSansProBold.getFamilyNames().contains("Source Sans Pro"));
  56. assertTrue(alexBrush.getFamilyNames().contains("Alex Brush"));
  57. }
  58. /**
  59. * Tests the number of glyphs and a select number of widths from each font
  60. */
  61. @Test
  62. public void testGlyphNumberAndWidths() {
  63. assertEquals(824, sourceSansProBold.numberOfGlyphs);
  64. assertEquals(256, alexBrush.numberOfGlyphs);
  65. int[] gids = {32, 42, 44, 47};
  66. int[] sourceSansWidths = {516, 555, 572, 383};
  67. for (int i = 0; i < gids.length; i++) {
  68. assertEquals(sourceSansWidths[i], sourceSansProBold.getWidths()[gids[i]]);
  69. }
  70. int[] carolynaWidths = {842, 822, 658, 784};
  71. for (int i = 0; i < gids.length; i++) {
  72. assertEquals(carolynaWidths[i], alexBrush.getWidths()[gids[i]]);
  73. }
  74. }
  75. @Test
  76. public void testBoundingBoxes() {
  77. assertEquals(sourceSansProBold.getBoundingBoxes()[0], new Rectangle(-231, -384, 1454, 1358));
  78. }
  79. }