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.

CharMetricsHandlerTestCase.java 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.type1;
  19. import java.awt.Rectangle;
  20. import java.io.IOException;
  21. import java.util.HashMap;
  22. import java.util.Map;
  23. import java.util.Stack;
  24. import org.junit.Test;
  25. import static org.mockito.Mockito.mock;
  26. import static org.mockito.Mockito.verify;
  27. import static org.mockito.Mockito.when;
  28. import org.apache.fop.fonts.NamedCharacter;
  29. import org.apache.fop.fonts.type1.AFMParser.ValueHandler;
  30. /**
  31. * Test case for {@link CharMetricsHandler}.
  32. */
  33. public class CharMetricsHandlerTestCase {
  34. private static final String GOOD_LINE = "C 32 ; WX 32 ; N space ; B 1 1 1 1";
  35. private static final AFMCharMetrics EXPECTED_CHM;
  36. static {
  37. EXPECTED_CHM = new AFMCharMetrics();
  38. EXPECTED_CHM.setCharCode(32);
  39. EXPECTED_CHM.setWidthX(32.0);
  40. EXPECTED_CHM.setCharacter(new NamedCharacter("space"));
  41. EXPECTED_CHM.setBBox(new Rectangle(1, 1, 0, 0));
  42. }
  43. @Test
  44. public void testHandlers() throws IOException {
  45. testEncodingWithMetricsLine("", GOOD_LINE);
  46. testEncodingWithMetricsLine("WrongEncoding", GOOD_LINE);
  47. testEncodingWithMetricsLine("AdobeStandardEncoding", GOOD_LINE);
  48. }
  49. private void testEncodingWithMetricsLine(String encoding, String line) throws IOException {
  50. Map<String, ValueHandler> valueParsers = mock(HashMap.class);
  51. ValueHandler cHandler = mock(ValueHandler.class);
  52. ValueHandler wxHandler = mock(ValueHandler.class);
  53. ValueHandler nHandler = mock(ValueHandler.class);
  54. ValueHandler bHandler = mock(ValueHandler.class);
  55. when(valueParsers.get("C")).thenReturn(cHandler);
  56. when(valueParsers.get("WX")).thenReturn(wxHandler);
  57. when(valueParsers.get("N")).thenReturn(nHandler);
  58. when(valueParsers.get("B")).thenReturn(bHandler);
  59. CharMetricsHandler handler = CharMetricsHandler.getHandler(valueParsers, encoding);
  60. Stack<Object> stack = new Stack<Object>();
  61. handler.parse(line, stack, null);
  62. verify(valueParsers).get("C");
  63. verify(valueParsers).get("WX");
  64. verify(valueParsers).get("N");
  65. verify(valueParsers).get("B");
  66. verify(cHandler).parse("32", 0, new Stack<Object>());
  67. verify(wxHandler).parse("32", 0, new Stack<Object>());
  68. verify(nHandler).parse("space", 0, new Stack<Object>());
  69. verify(bHandler).parse("1 1 1 1", 0, new Stack<Object>());
  70. }
  71. }