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.

CIDFullTestCase.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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;
  19. import java.util.BitSet;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import org.junit.Before;
  23. import org.junit.Test;
  24. import static org.junit.Assert.assertArrayEquals;
  25. import static org.junit.Assert.assertEquals;
  26. import static org.junit.Assert.assertTrue;
  27. import static org.mockito.Mockito.mock;
  28. import static org.mockito.Mockito.when;
  29. import org.apache.fop.util.CharUtilities;
  30. public class CIDFullTestCase {
  31. private CIDFull cidFull;
  32. private MultiByteFont mbFont;
  33. private BitSet bs;
  34. private char[] chars;
  35. private int[] widths;
  36. private Map<Integer, Integer> glyphs;
  37. @Before
  38. public void setup() {
  39. bs = new BitSet();
  40. glyphs = new HashMap<Integer, Integer>();
  41. chars = new char[18];
  42. widths = new int[18];
  43. int i = 0;
  44. for (int j = 0; j < 20; j++) {
  45. if (j == 10 || j == 11) {
  46. continue;
  47. }
  48. bs.set(j);
  49. glyphs.put(j, j);
  50. chars[i] = (char) j;
  51. widths[i] = 100;
  52. i++;
  53. }
  54. mbFont = mock(MultiByteFont.class);
  55. when(mbFont.getGlyphIndices()).thenReturn(bs);
  56. when(mbFont.getChars()).thenReturn(chars);
  57. when(mbFont.getWidths()).thenReturn(widths);
  58. cidFull = new CIDFull(mbFont);
  59. }
  60. @Test
  61. public void testGetOriginalGlyphIndex() {
  62. // index 5 exists
  63. assertEquals(cidFull.getOriginalGlyphIndex(5), 5);
  64. }
  65. @Test
  66. public void testGetUnicode() {
  67. // index 9 exists
  68. assertEquals(cidFull.getUnicode(9), (char) 9);
  69. // index 10 does not
  70. assertEquals(cidFull.getUnicode(10), CharUtilities.NOT_A_CHARACTER);
  71. }
  72. @Test
  73. public void testMapChar() {
  74. // index 9 exists
  75. char c = 'a';
  76. assertEquals(cidFull.mapChar(9, c), (char) 9);
  77. }
  78. @Test
  79. public void testMapCodePoint() {
  80. // index 9 exists
  81. char c = 'a';
  82. assertEquals(cidFull.mapCodePoint(9, c), (char) 9);
  83. }
  84. @Test
  85. public void testGetGlyphs() {
  86. Map<Integer, Integer> fontGlyphs = cidFull.getGlyphs();
  87. for (Map.Entry<Integer, Integer> integerIntegerEntry : fontGlyphs.entrySet()) {
  88. assertEquals(integerIntegerEntry.getValue(), glyphs.get(integerIntegerEntry.getKey()));
  89. }
  90. assertTrue(fontGlyphs.size() == glyphs.size());
  91. }
  92. @Test
  93. public void testGetChars() {
  94. assertArrayEquals(cidFull.getChars(), chars);
  95. }
  96. @Test
  97. public void testGetNumberOfGlyphs() {
  98. assertTrue(cidFull.getNumberOfGlyphs() == 20);
  99. }
  100. @Test
  101. public void testGetGlyphIndices() {
  102. assertEquals(bs, cidFull.getGlyphIndices());
  103. }
  104. @Test
  105. public void testGetWidths() {
  106. assertArrayEquals(cidFull.getWidths(), widths);
  107. }
  108. }