1. /*
  2. * @(#)ArabicLigaturizer.java 1.3 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. /*
  8. * @(#)ArabicLigaturizer.java 1.1 98/07/31
  9. *
  10. * (C) Copyright IBM Corp. 1998 - All Rights Reserved
  11. */
  12. package javax.swing.text;
  13. import java.io.BufferedInputStream;
  14. import java.io.DataInputStream;
  15. import java.io.InputStream;
  16. import java.io.IOException;
  17. /**
  18. * A factory for two arabic ligaturizers. One generates all the
  19. * compatibility arabic ligatures, the other only lam-alef ligatures.
  20. */
  21. /*
  22. * Source data is in resource arabiclig.data as an unsigned short count of
  23. * the number of chars, followed by the chars. The fallback ligaturizer
  24. * generates only the lam-alef ligatures from fef5-fefc.
  25. */
  26. class ArabicLigaturizer {
  27. private static Ligaturizer singleton;
  28. private static Ligaturizer lasingleton;
  29. static Ligaturizer getInstance() {
  30. if (singleton == null) {
  31. singleton = new CharBasedLigaturizer(getData());
  32. }
  33. return singleton;
  34. }
  35. static Ligaturizer getLamAlefInstance() {
  36. if (lasingleton == null) {
  37. lasingleton = new CharBasedLigaturizer(getLamAlefData());
  38. }
  39. return lasingleton;
  40. }
  41. private ArabicLigaturizer() {
  42. }
  43. private static char[] data = null;
  44. protected static char[] getData() {
  45. if (data == null) {
  46. InputStream in = ArabicLigaturizer.class.getResourceAsStream("/arabiclig.data");
  47. try {
  48. BufferedInputStream inbuf = new BufferedInputStream(in);
  49. DataInputStream indat = new DataInputStream(inbuf);
  50. int len = indat.readInt();
  51. char[] temp = new char[len];
  52. for (int i = 0; i < len; i++) {
  53. temp[i] = indat.readChar();
  54. }
  55. data = temp;
  56. }
  57. catch (IOException e) {
  58. data = getLamAlefData();
  59. }
  60. }
  61. return data;
  62. }
  63. private static char[] lamalef = null;
  64. protected static char[] getLamAlefData() {
  65. // note "\\u0022" performs the \\ before the unicode expansion
  66. // (at least in 1.1.6), expanding this to 5 chars
  67. // so we use \" instead
  68. if (lamalef == null) {
  69. lamalef = (
  70. "\uffff\uffff\u0004\u0007\u0012\u001d\u0028\ufe82" +
  71. "\uffff\u0002\u000c\u000f\ufedf\ufef5\u0000\ufee0" +
  72. "\ufef6\u0000\ufe84\uffff\u0002\u0017\u001a\ufedf" +
  73. "\ufef7\u0000\ufee0\ufef8\u0000\ufe88\uffff\u0002" +
  74. "\"\u0025\ufedf\ufef9\u0000\ufee0\ufefa\u0000" +
  75. "\ufe8e\uffff\u0002\u002d\u0030\ufedf\ufefb\u0000" +
  76. "\ufee0\ufefc\u0000").toCharArray();
  77. }
  78. return lamalef;
  79. }
  80. /*
  81. static void main(String[] args) {
  82. char[] src = " \u0644\0627 ".toCharArray();
  83. Ligaturizer al = ArabicLigaturizer.getInstance();
  84. al = al.restrict(new Ligaturizer.Filter() {
  85. boolean accepts(char c) {
  86. return c >= '\ufef5' && c <= '\ufefc';
  87. }
  88. });
  89. System.out.println("restricted ligaturizer");
  90. System.out.println(al);
  91. System.out.println("lam alef ligaturizer");
  92. System.out.println(getLamAlefInstance());
  93. }
  94. */
  95. }