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.

KhmerTestCase.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.complexscripts.scripts;
  19. import java.util.Arrays;
  20. import java.util.Collections;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Map;
  24. import org.junit.Assert;
  25. import org.junit.Test;
  26. import static org.junit.Assert.assertEquals;
  27. import org.apache.fop.complexscripts.fonts.GlyphCoverageTable;
  28. import org.apache.fop.complexscripts.fonts.GlyphPositioningTable;
  29. import org.apache.fop.complexscripts.fonts.GlyphSubtable;
  30. import org.apache.fop.complexscripts.fonts.GlyphTable;
  31. import org.apache.fop.complexscripts.fonts.OTFLanguage;
  32. import org.apache.fop.complexscripts.fonts.OTFScript;
  33. import org.apache.fop.complexscripts.util.CharScript;
  34. import org.apache.fop.complexscripts.util.GlyphSequence;
  35. import org.apache.fop.fonts.MultiByteFont;
  36. public class KhmerTestCase {
  37. @Test
  38. public void testProcessor() {
  39. String in = "\u179b\u17c1\u1781\u179a\u17c0\u1784\u17b7\u179c\u17d2\u1780\u1780\u1799\u1794\u17d2\u178f\u179a";
  40. String out =
  41. "\u17c1\u179b\u1781\u17c1\u179a\u17c0\u1784\u17b7\u179c\u17d2\u1780\u1780\u1799\u1794\u17d2\u178f\u179a";
  42. assertEquals(
  43. new KhmerScriptProcessor(OTFScript.KHMER).preProcess(in, new MultiByteFont(null, null), null), out);
  44. }
  45. @Test
  46. public void testPositioning() {
  47. GlyphSubtable subtable5 = GlyphPositioningTable.createSubtable(5, "lu1", 0, 0, 1,
  48. GlyphCoverageTable.createCoverageTable(Collections.singletonList(0)),
  49. Arrays.asList(
  50. GlyphCoverageTable.createCoverageTable(Collections.singletonList(0)),
  51. 0,
  52. 1,
  53. new GlyphPositioningTable.MarkAnchor[] {
  54. new GlyphPositioningTable.MarkAnchor(0, new GlyphPositioningTable.Anchor(0, 0))
  55. },
  56. new GlyphPositioningTable.Anchor[][][] {
  57. new GlyphPositioningTable.Anchor[][] {
  58. new GlyphPositioningTable.Anchor[] {
  59. new GlyphPositioningTable.Anchor(12, 0)
  60. }
  61. }
  62. }
  63. ));
  64. Map<GlyphTable.LookupSpec, List> lookups = new HashMap<GlyphTable.LookupSpec, List>();
  65. lookups.put(new GlyphTable.LookupSpec(OTFScript.KHMER, OTFLanguage.DEFAULT, "abvm"),
  66. Collections.singletonList("lu1"));
  67. Map<String, ScriptProcessor> processors = new HashMap<String, ScriptProcessor>();
  68. processors.put(OTFScript.KHMER, new KhmerScriptProcessor(OTFScript.KHMER));
  69. GlyphPositioningTable gpt =
  70. new GlyphPositioningTable(null, lookups, Collections.singletonList(subtable5), processors);
  71. ScriptProcessor scriptProcessor = ScriptProcessor.getInstance(OTFScript.KHMER, processors);
  72. MultiByteFont multiByteFont = new MultiByteFont(null, null);
  73. GlyphSequence glyphSequence = multiByteFont.charSequenceToGlyphSequence("test", null);
  74. scriptProcessor.preProcess("test", multiByteFont, null);
  75. scriptProcessor.substitute(
  76. glyphSequence, OTFScript.KHMER, OTFLanguage.DEFAULT, new GlyphTable.UseSpec[0], null);
  77. int[][] adjustments = new int[4][1];
  78. gpt.position(glyphSequence, OTFScript.KHMER, OTFLanguage.DEFAULT, 0, null, adjustments);
  79. Assert.assertArrayEquals(adjustments[1], new int[]{12});
  80. }
  81. @Test
  82. public void testMakeProcessor() {
  83. Assert.assertTrue(IndicScriptProcessor.makeProcessor(OTFScript.KHMER) instanceof KhmerScriptProcessor);
  84. Assert.assertTrue(CharScript.isIndicScript(OTFScript.KHMER));
  85. }
  86. @Test
  87. public void testKhmerRenderer() {
  88. KhmerRenderer khmerRenderer = new KhmerRenderer();
  89. StringBuilder stringBuilder = new StringBuilder();
  90. int khmerStart = 6016;
  91. for (int i = khmerStart; i < khmerStart + 128; i++) {
  92. stringBuilder.append((char)i);
  93. }
  94. String allKhmerChars = stringBuilder.toString();
  95. String expected = khmerRenderer.render(allKhmerChars);
  96. assertEquals(expected.length(), 133);
  97. StringBuilder diff = new StringBuilder();
  98. for (int i = 0; i < allKhmerChars.length(); i++) {
  99. if (allKhmerChars.charAt(i) != expected.charAt(i)) {
  100. diff.append(expected.charAt(i));
  101. }
  102. }
  103. assertEquals(diff.length(), 66);
  104. assertEquals(diff.charAt(0), (char) 6081);
  105. }
  106. }