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.

KhmerScriptProcessor.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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.List;
  20. import org.apache.fop.complexscripts.fonts.GlyphDefinitionTable;
  21. import org.apache.fop.complexscripts.fonts.GlyphTable;
  22. import org.apache.fop.complexscripts.util.CharAssociation;
  23. import org.apache.fop.complexscripts.util.GlyphContextTester;
  24. import org.apache.fop.complexscripts.util.GlyphSequence;
  25. import org.apache.fop.complexscripts.util.ScriptContextTester;
  26. import org.apache.fop.fonts.MultiByteFont;
  27. /**
  28. * <p>The <code>KhmerScriptProcessor</code> class implements a script processor for
  29. * performing glyph substitution and positioning operations on content associated with the Khmer script.</p>
  30. */
  31. public class KhmerScriptProcessor extends IndicScriptProcessor {
  32. private GlyphSequence unprocessedGS;
  33. private List associations;
  34. private int[] chars;
  35. KhmerScriptProcessor(String script) {
  36. super(script);
  37. }
  38. protected Class<? extends IndicScriptProcessor.DefaultSyllabizer> getSyllabizerClass() {
  39. return KhmerSyllabizer.class;
  40. }
  41. private static class KhmerSyllabizer extends DefaultSyllabizer {
  42. KhmerSyllabizer(String script, String language) {
  43. super(script, language);
  44. }
  45. }
  46. @Override
  47. public GlyphSequence reorderCombiningMarks(GlyphDefinitionTable gdef, GlyphSequence glyphSequence,
  48. int[] unscaledWidths, int[][] glyphPositionAdjustments, String script,
  49. String language) {
  50. return glyphSequence;
  51. }
  52. public CharSequence preProcess(CharSequence charSequence, MultiByteFont font, List associations) {
  53. unprocessedGS = font.charSequenceToGlyphSequence(charSequence, associations);
  54. return new KhmerRenderer().render(charSequence.toString());
  55. }
  56. public boolean position(GlyphSequence glyphSequence, String script, String language, int fontSize,
  57. GlyphTable.UseSpec[] useSpecs, int[] widths, int[][] adjustments,
  58. ScriptContextTester scriptContextTester) {
  59. glyphSequence.setUnprocessedGS(unprocessedGS);
  60. return super.position(glyphSequence, script, language, fontSize, useSpecs, widths, adjustments,
  61. scriptContextTester);
  62. }
  63. public GlyphSequence substitute(GlyphSequence glyphSequence, String script, String language,
  64. GlyphTable.UseSpec[] useSpecs, ScriptContextTester scriptContextTester) {
  65. glyphSequence = super.substitute(glyphSequence, script, language, useSpecs, scriptContextTester);
  66. associations = glyphSequence.getAssociations();
  67. chars = glyphSequence.getCharacters().array();
  68. return glyphSequence;
  69. }
  70. private ScriptContextTester scriptContextTester = new ScriptContextTester() {
  71. private GlyphContextTester tester = new GlyphContextTester() {
  72. public boolean test(String script, String language, String feature, GlyphSequence glyphSequence, int index,
  73. int flags) {
  74. CharAssociation charAssociation = (CharAssociation) associations.get(index);
  75. char vowelSignU = '\u17BB';
  76. for (int i = charAssociation.getStart(); i < charAssociation.getEnd(); i++) {
  77. if (chars[i] == vowelSignU) {
  78. return false;
  79. }
  80. }
  81. return true;
  82. }
  83. };
  84. public GlyphContextTester getTester(String feature) {
  85. return tester;
  86. }
  87. };
  88. public ScriptContextTester getPositioningContextTester() {
  89. return scriptContextTester;
  90. }
  91. }