1 18 package org.apache.batik.gvt.font; 19 20 import java.util.Arrays ; 21 22 30 public class Kern { 31 32 private int[] firstGlyphCodes; 33 private int[] secondGlyphCodes; 34 private UnicodeRange[] firstUnicodeRanges; 35 private UnicodeRange[] secondUnicodeRanges; 36 private float kerningAdjust; 37 38 55 public Kern(int[] firstGlyphCodes, 56 int[] secondGlyphCodes, 57 UnicodeRange[] firstUnicodeRanges, 58 UnicodeRange[] secondUnicodeRanges, 59 float adjustValue) { 60 this.firstGlyphCodes = firstGlyphCodes; 61 this.secondGlyphCodes = secondGlyphCodes; 62 this.firstUnicodeRanges = firstUnicodeRanges; 63 this.secondUnicodeRanges = secondUnicodeRanges; 64 this.kerningAdjust = adjustValue; 65 66 if (firstGlyphCodes != null) 67 Arrays.sort(this.firstGlyphCodes); 68 if (secondGlyphCodes != null) 69 Arrays.sort(this.secondGlyphCodes); 70 } 71 72 81 public boolean matchesFirstGlyph(int glyphCode, String glyphUnicode) { 82 if (firstGlyphCodes != null) { 83 int pt = Arrays.binarySearch(firstGlyphCodes, glyphCode); 84 if (pt >= 0) return true; 85 } 86 if (glyphUnicode.length() < 1) return false; 87 char glyphChar = glyphUnicode.charAt(0); 88 for (int i = 0; i < firstUnicodeRanges.length; i++) { 89 if (firstUnicodeRanges[i].contains(glyphChar)) 90 return true; 91 } 92 return false; 93 } 94 95 104 public boolean matchesFirstGlyph(int glyphCode, char glyphUnicode) { 105 if (firstGlyphCodes != null) { 106 int pt = Arrays.binarySearch(firstGlyphCodes, glyphCode); 107 if (pt >= 0) return true; 108 } 109 for (int i = 0; i < firstUnicodeRanges.length; i++) { 110 if (firstUnicodeRanges[i].contains(glyphUnicode)) 111 return true; 112 } 113 return false; 114 } 115 116 126 public boolean matchesSecondGlyph(int glyphCode, String glyphUnicode) { 127 if (secondGlyphCodes != null) { 128 int pt = Arrays.binarySearch(secondGlyphCodes, glyphCode); 129 if (pt >= 0) return true; 130 } 131 if (glyphUnicode.length() < 1) return false; 132 char glyphChar = glyphUnicode.charAt(0); 133 for (int i = 0; i < secondUnicodeRanges.length; i++) { 134 if (secondUnicodeRanges[i].contains(glyphChar)) 135 return true; 136 } 137 return false; 138 } 139 140 150 public boolean matchesSecondGlyph(int glyphCode, char glyphUnicode) { 151 if (secondGlyphCodes != null) { 152 int pt = Arrays.binarySearch(secondGlyphCodes, glyphCode); 153 if (pt >= 0) return true; 154 } 155 for (int i = 0; i < secondUnicodeRanges.length; i++) { 156 if (secondUnicodeRanges[i].contains(glyphUnicode)) 157 return true; 158 } 159 return false; 160 } 161 162 168 public float getAdjustValue() { 169 return kerningAdjust; 170 } 171 172 } 173 | Popular Tags |